package com.tkjt.pms.calc.common;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;

public class CalcDepartDepens {

	private Map<String, Map<Integer, Set<String>>> departDepenChains = new HashMap<String, Map<Integer, Set<String>>>();

	public void addOneDepenChain(String orgCode, LinkedList<String> depenList) {
		Map<Integer, Set<String>> tempMap = departDepenChains.get(orgCode);
		if (null == tempMap) {
			tempMap = new HashMap<Integer, Set<String>>();
			departDepenChains.put(orgCode, tempMap);
		}
		for(int index=0;index<depenList.size();index++) {
			Set<String> tempSet = tempMap.get(Integer.valueOf(index+1));
			if(null==tempSet) {
				tempSet = new HashSet<String>();
				tempMap.put(Integer.valueOf(index+1), tempSet);
			}
			tempSet.add(depenList.get(index));
		}
	}

	public boolean hasDepenChain(String orgCode) {
		return departDepenChains.containsKey(orgCode);
	}

	public Integer getDepenChainLevel(String orgCode) {
		return departDepenChains.get(orgCode).size();
	}

	public Set<String> getDepenChainLevelCodes(String orgCode, Integer depenLevel) {
		Set<String> tempSet = departDepenChains.get(orgCode).get(depenLevel);
		if (null == tempSet) {
			return new HashSet<String>();
		}
		return tempSet;
	}

	public void removeDepenChain(String orgCode) {
		departDepenChains.remove(orgCode);
	}

}
